<?php
namespace Admin\Controller;

class CashController extends AdminController{
    public function index(){
        Cookie('__forward__', $_SERVER['REQUEST_URI']);

        $cash=M('cash');
       $list=$this->lists('cash');
        if($list){
            $m_member=M('member');
            $m_bank_card=M('bank_card');
            int_to_string($list,array('status'=>array(0=>'未完成',1=>'已完成')));
            foreach($list as &$item){
                $item['nickname']=$m_member->where(array('uid'=>$item['uid']))->getField('nickname');
                $card=$m_bank_card->where(array('id'=>$item['bank_card_id']))->field('bank_title,card_no,true_name')->find();
                if($card){
//                    $item['bank']=$card['bank'];
//                    $item['card_no']=$card['card_no'];
//                    $item['owner']=$card['owner'];
                    $item=array_merge($item,$card);
                }
            }
            $this->assign('clist',$list);
        }
        $this->display();
    }

    public function edit(){
        if(IS_POST){
           $status=I('status');
            $id=I("id");
            if($id){
                $m_cash=M('cash');
                $result=$m_cash->where(array('id'=>$id))->setField('status',$status);
                $result && $this->success('保存成功',Cookie('__forward__'));
            }
            else
                $this->error('提现内容不存在',Cookie('__forward__'));
        }else{
        $cid=I('id',0);

        if($cid){
            $m_cash=M('cash');
            $m_member=M('member');
            $m_bank_card=M('bank_card');
            $info=$m_cash->where(array('id'=>$cid))->find();
            if($info){
                $info['nickname']=get_nickname($info['uid']);
                $card=$m_bank_card->where(array('id'=>$info['bank_card_id']))->field('bank_title,card_no,true_name')->find();
                
                $card && $info=array_merge($info,$card);
                $this->assign('info',$info);
                $this->display();
            }else
                $this->error('提现内容不存在',Cookie('__forward__'));
        }
        else{
            $this->error('提现内容不存在',Cookie('__forward__'));
        }
    }}
}
?>